/**
 * @AccessTcpClientEndpoint.java  COPYRIGHT xiaojian
 * 
 * Created on 2017年7月9日 下午8:53:14
 */
package xj.toolkit.access.connector;

import io.netty.channel.ChannelHandlerContext;
import xj.toolkit.netty.transport.endpoint.DefaultClientEndpoint;
import xj.toolkit.access.AccessHeader;
import xj.toolkit.access.msg.AccessAckMessage;
import xj.toolkit.access.msg.AccessMessage;

/**
 * Access的endpoint。
 * 
 * @author <a href="mailto:cxj2000@gmail.com">xiaojian.cao</a>
 *
 */
public class AccessTcpClientEndpoint extends DefaultClientEndpoint<AccessMessage> {

	/**
	 * 业务模块的模块Id。
	 */
	private short busiModuleId = 0x0;

	/**
	 * 业务模块的instanceId。
	 */
	private short busiInstanceId = 0x0;

	public short getBusiModuleId() {
		return busiModuleId;
	}

	public short getBusiInstanceId() {
		return busiInstanceId;
	}

	/**
	 * 消息接收到之后。
	 */
	public void messageReceived(ChannelHandlerContext ctx, AccessMessage msg) {
		// 发送过来的确认消息
		if (msg instanceof AccessAckMessage) {
			AccessAckMessage ackMessage = (AccessAckMessage) msg;
			AccessHeader accessHeader = ackMessage.getAccessHeader();
			busiModuleId = accessHeader.getSourceModuleId();
			busiInstanceId = accessHeader.getSourceInstanceId();
		}

		super.messageReceived(ctx, msg);
	}
}
